package com.cizzy.video.entity.dto;

import com.cizzy.video.entity.dao.UserDAO;
import com.cizzy.video.entity.dao.VideoDAO;
import com.cizzy.video.entity.dao.VideoCountDAO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.*;
import java.sql.Timestamp;

/**
 * @author 51755
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VideoDTO implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

//    @TableId("video_id")

    private Long videoId;

    private Timestamp createAt;

    private String title;

    private String description;

    private String cryptoTitle;

    private String type;

    private Long favoriteCount;

    private Long commentCount;

    private Long shareCount;

    private String videoUrl;

    private UserDTO author = new UserDTO();

    public VideoDTO(VideoDAO video, VideoCountDAO videoCount, UserDAO user) {
        this.convertFromVideoDAO(video);
        this.convertFromVideoCountDAO(videoCount);
        this.convertFromUserDAO(user);
    }

    public void convertFromVideoDAO(VideoDAO video) {
        this.videoId = video.getVideoId();
        this.createAt = video.getCreateAt();
        this.title = video.getTitle();
        this.description = video.getDescription();
        this.cryptoTitle = video.getCryptoTitle();
        this.type = video.getType();
        this.videoUrl = video.getVideoUrl();
    }

    public void convertFromVideoCountDAO(VideoCountDAO videoCount) {
        this.favoriteCount = videoCount.getFavoriteCount();
        this.commentCount = videoCount.getCommentCount();
        this.shareCount = videoCount.getShareCount();
    }

    public void convertFromUserDAO(UserDAO user) {
        this.author.setUserId(user.getUserId());
        this.author.setSignature(user.getSignature());
        this.author.setNickname(user.getNickname());
        this.author.setAvatar(user.getAvatar());
    }
}
